package com.kmg.scart.model;

import java.sql.Date;
import java.util.HashSet;
import java.util.Set;

public class Cart extends ApplicationEntity{

	private Date creationTime;
	
	private User owner;
	
	private long ownerId;
	
	private Set<CartItem> items = new HashSet<CartItem>(0);
	
	private double totalValue;
	
	private CartStatus status;

	private Date lastModified;
	
	public Date getCreationTime() {
		return creationTime;
	}

	public void setCreationTime(Date creationTime) {
		this.creationTime = creationTime;
	}

	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		this.owner = owner;
		this.ownerId=owner.getId();
	}

	public Set<CartItem> getItems() {
		return items;
	}

	public double getTotalValue() {
		return totalValue;
	}

	public void setTotalValue(double totalValue) {
		this.totalValue = totalValue;
	}

	public CartStatus getStatus() {
		return status;
	}

	public void setStatus(CartStatus status) {
		this.status = status;
	}
	
	public void addToCart(Product prod,int qty){
		CartItem item = new CartItem();
		item.setDateAdded(new Date(System.currentTimeMillis()));
		item.setProduct(prod);
		item.setQty(qty);
		items.add(item);
	}

	public Date getLastModified() {
		return lastModified;
	}

	public void setLastModified(Date lastModified) {
		this.lastModified = lastModified;
	}

	public long getOwnerId() {
		return ownerId;
	}

	public void setOwnerId(long ownerId) {
		this.ownerId = ownerId;
	}
}
